package com.song.mscloud.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.stereotype.Component;

/**
 * @author TonySong
 * @date 2024/5/7 0007
 * @time 16:28
 */
@Component
@Slf4j
public class CheckAuthGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {


    @Override
    public GatewayFilter apply(NameValueConfig config) {
         return (exchange, chain) -> {
             log.info("CheckAuthGatewayFilterFactory");
             String name=config.getName();
             String pwd = config.getValue();
             log.info(config.getName());
             log.info(config.getValue());
             if(name.equalsIgnoreCase("tom")  && pwd.equalsIgnoreCase("123")) {
                 return chain.filter(exchange);
             }else{
                 log.info("权限不足");
                 return exchange.getResponse().setComplete();
             }

         };
    }
}
